package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SaleListGoodsDao;
import com.atguigu.jxc.entity.SaleListGoods;
import javax.annotation.Resource;
import java.util.HashMap;
import com.atguigu.jxc.service.SaleListGoodsService;
import com.atguigu.jxc.to.SaleCountTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/** @ClassName:SaleListGoodsServiceImpl
 * @Version: 1.0
 * @CreateAt:2021/3/8 19:50
 * @Author: ✨HanSan·胡✨
 * @Description:
 */
@Service
public class SaleListGoodsServiceImpl implements SaleListGoodsService {

    @Autowired
    private SaleListGoodsDao saleListGoodsDao;

    @Override
    public List<Map> getSaleDataByDay(String sTime, String eTime) {
        List<Map> list = saleListGoodsDao.getSaleDataByDay(sTime,eTime);
        return list;
    }

    @Override
    public List<Map> count(SaleCountTo saleCountTo) {
        String codeOrName = saleCountTo.getCodeOrName();
        if(null!=codeOrName && !"".equals(codeOrName)){
            try {
                int i = Integer.parseInt(codeOrName);
                saleCountTo.setStatus(1);
            }catch (Exception e){
                saleCountTo.setStatus(2);
            }
        }

        List<Map> list = saleListGoodsDao.count(saleCountTo);
        return list;
    }

    @Override
    public void add(SaleListGoods saleListGoods) {
        saleListGoodsDao.save(saleListGoods);


    }

    @Override
    public Map<String, Object> goodsListBySaleListId(Integer saleListId) {
        List<SaleListGoods> saleListGoods = saleListGoodsDao.goodsListBySaleListId(saleListId);
        Map<String, Object> map = new HashMap<>();
        map.put("rows", saleListGoods);
        return map;
    }

}
